package com.sample.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.View;

import com.base.sampleproject.R;

/**
 * Created by devnn on 16/1/25.
 */
public class CircleLukyDrawView extends View{
    private Context context;
    private Paint paint;
    public CircleLukyDrawView(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context=context;
        paint=new Paint();

    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        paint.setColor(ContextCompat.getColor(context, R.color.color_deep_green));
        paint.setStrokeWidth(5);
        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawCircle(getWidth() / 2, getHeight() / 2, (getWidth() - 10) / 2, paint);
        paint.setStrokeWidth(10);
        canvas.drawLine(getWidth() / 2, getHeight() / 2, getWidth() / 2, 110, paint);
//        canvas.drawLine(getWidth() / 2 - 50, 100, getWidth() / 2, 50, paint);
        Path path=new Path();
        path.moveTo(getWidth() / 2 - 30, 110);
        path.lineTo(getWidth() / 2 + 30, 110);
        path.lineTo(getWidth() / 2, 70);
        path.close();
        paint.setStyle(Paint.Style.FILL);
        canvas.drawPath(path, paint);
        paint.setTextSize(25);
        canvas.rotate(0);
        canvas.drawText("奖品1", getWidth() / 2, 50, paint);
//        canvas.drawText("奖品" + 1, getWidth() / 2 + (1 - 1) * getWidth() / (2 * 5), 50 + (1 - 1) * getHeight() / 10, paint);

        canvas.translate(getWidth()/2,getHeight()/2);
        canvas.rotate(90);
        canvas.drawText("奖品2" + 2, getWidth()/2, 100,paint);
//        for(int i=1;i<=5;i++){
//            canvas.rotate((i-1)*18);
//            canvas.drawText("奖品"+i,getWidth()/2+(i-1)*getWidth()/(2*5),50+(i-1)*getHeight()/10,paint);
//        }
//        canvas.drawLine(getWidth() / 2,getHeight()/2,getWidth()/2,50,paint);
    }
}
